<?php
/**
 * Created by PhpStorm.
 * User: apple
 * Date: 2020/10/12
 * Time: 4:06 PM
 */
namespace app\index\logic;

use app\model\Organization;
use app\model\Token;
use app\model\User;
use app\model\UserSign;
use think\facade\Db;
use think\facade\Request;

class AdminLogic
{
    /*
     * 管理员 登录
     */
    public static function login($phone,$pwd)
    {
        $where = [
            ['position','in',[User::SYS_ADMIN]],
            ['phone','=',$phone],
        ];
        $userModel = new User();
        $info = $userModel->getUserAdminInfoByWhere($where,'user.id,user.pername,user.phone,user.pwd,user.position,user.orgid,org.orgname');

        if(!$info)  fail('账号不存在');
        $userPwd = $info['pwd'];
        unset($info['pwd']);
        if($userPwd != encode($pwd))    fail('账号密码错误');

        $tokenModel = new Token();
        $rt['token'] = $tokenModel->generateToken($info['id']);
        //组织列表
        $orgModel = new Organization();
        $rt['org'] = $orgModel->getOrgListByOrgId();

        success($rt);
    }

    public static function signReport($where)
    {
        $userSignModel = new UserSign();
        return $userSignModel->getOrgSignListByWhere($where);
    }
}